Ext.namespace("yft.sysMember");
var sysMemberListStore_1 = new Ext.data.JsonStore({
		url:basepath+"/yft/sysMember/getSysMemberList.html",
		root:'root',
		totalProperty:'totalProperty',  
		fields:[
				{name: 'id'},
				{name: 'loginID'},
				{name: 'realName'},
				{name: 'mobile'},
				{name: 'tel'},
				{name: 'telCode'},
				{name: 'email'},
				{name: 'realName'},
				{name: 'lastLoginIp'},
				{name: 'isWarehouse'},
				{name: 'warehouseId'},
				{name: 'lastLoginTime'},
				{name: 'sex'}
		]  
	});	
function addSysMember(){
	var btnOk =new Ext.Button({
		minWidth:70,
		id:'btnOkId',
		text:"确定",
		handler: submitPanel
	});
	var btnClear=new Ext.Button({
		minWidth:70,
		text:"清空",
		handler: clearPanel
	});
	var btnClose=new Ext.Button({
		minWidth:70,
		text:"关闭",
		handler: closeWin
	});
	var combox_arr =[['MALE','男'],['FEMALE','女']];
	var DateStore = new Ext.data.SimpleStore({
		data:combox_arr,
		fields:["sexValue","sexDis"]
	});

	var contSubmitPanel =new Ext.form.FormPanel({
		frame : true,
		defaults:{labelWidth:60,labelAlign:"right"},
		buttonAlign:'center',
		items:[{
			xtype : 'fieldset',
			 autoHeight : true,
			 items:[{
				 		layout : 'form',
						border : false,
						columnWidth : .5,
						items:[
							{height:8},
								{
									xtype:'textfield',
									name : 'name',
									fieldLabel : '用户姓名',
									labelStyle:labelStyle+" width:60",
									allowBlank : false,
									blankText : '用户姓名为必填项',
									width : 150,
									style:'float:left;padding-left:0px;'
								},
								{
									xtype:'textfield',
									name : 'loginId',
									fieldLabel : '登录账户',
									labelStyle:labelStyle+" width:60",
									regex:/^[^\u4e00-\u9fa5]{0,}$/,
									allowBlank : false,
									blankText : '登录账户为必填项',
									width : 150,
									style:'float:left;padding-left:0px;'
								},
								{
									xtype:'textfield',
									//inputType:'password',
									name : 'password',
									labelStyle:labelStyle+" width:60;",
									fieldLabel : '登录密码',
									allowBlank : false,
									blankText : '登录密码为必填项',
									width : 150,maxLength:16,minLength:3,
									style:'float:left;padding-left:0px;'
								},
								{
									xtype:'textfield',
									name : 'email',
									fieldLabel : '邮箱',
									labelStyle:labelStyle+" width:60",
									allowBlank : false,
									blankText : '邮箱为必填项',
									vtype:'email',
									width : 150,maxLength:58,
									style:'float:left;padding-left:0px;'
								},
								{
									width:150,
									fieldLabel : '性别',
									xtype:'combo',
									name:'sex',
									store:DateStore,
									displayField:'sexDis',
									labelStyle:labelStyle+" width:60;",
									valueField:'sexValue',
									forceSelection:true,
									triggerAction:'all',
									emptyText:'------请选择------',
									editable:false,
									mode:'local',
									allowBlank:false,
									blankText:'性别不能为空',
									ctCls:'xingbie' 
								},
								{
									xtype:'numberfield',
									allowNegative:false,
									allowDecimals :false,
									regex:/^(1\d{10})$/,
									regexText:'手机输入不正确',
									fieldLabel:'移动手机',
									id:'mobile',
									maxLength:11,
									name:'mobile',
									width:150,
									style:'float:left;padding-left:0px;'
					         },{
					        	 height:25,
						         layout:'table',layoutConfig:{column:3},
						         items:[{
						         			html:'<span style="font-size:12px; text-align:right; width:57px; float:left; margin-right:8px; padding:3px 0px 3px 0; position: relative;">固定电话:</span>'
						        		 },{
						         			 height:20,
											 xtype:'textfield',
											 allowNegative:false,
											 allowDecimals :false,
											 regex:/^\d{2,4}$/,
										 	 regexText:'电话区号输入不正确',
						         			 width:42,
						         			 id:'telzone',
						         			 maxLength:4,
						         			 name:'telzone'
						         		},{
						         			html:'-'
						         		},{
										 height:20,
										 xtype:'numberfield',
										 allowNegative:false,
										 allowDecimals :false,
										 regex:/^\d{6,9}$/,
										 regexText:'电话号码输入不正确',
										 id:'telphone',
										 name:'telphone',
										 maxLength:8,
										 width:102
									}]
					    	}
						]
			 }]
		}],
		buttons:[btnOk,btnClear,btnClose]
	});
	var win =new Ext.Window({
		title:'操作用户信息添加',
		width: 266,
		items: contSubmitPanel,
        closeAction:'close',
		maskDisabled:true,
		resizable:false,
		autoScroll: false,
		draggable:true,
		modal: true,
		bodyStyle: my_scroll_cs
	});
	win.show();
	function submitPanel(){
		var submitButtonXsl = Ext.getCmp('btnOkId');
		submitButtonXsl.setDisabled(true);
		if(contSubmitPanel.form.isValid()){
			var phone = Ext.getCmp('mobile').getValue();
			var telzone =  Ext.getCmp('telzone').getValue();
			var telphone =  Ext.getCmp('telphone').getValue();
			if(telzone=='' && telphone !=''){
				submitButtonXsl.setDisabled(false);
				Ext.MessageBox.alert("提示","电话号码前的区号不能为空");
				return;
			}
			if(phone=='' && telphone==''){
				submitButtonXsl.setDisabled(false);
				Ext.MessageBox.alert("提示","电话号码和手机号码不能同时为空");
				return;
			}
			contSubmitPanel.form.submit({
				waitTitle : '请稍候',
				waitMsg : '正在保存......',
				url :basepath+"/yft/sysMember/addSysMember.html",
				success : function(form, action) {
					Ext.MessageBox.alert("系统消息", '恭喜您！操作已成功！', function(btn) {
						if(btn =='ok'){
							sysMemberListStore_1.reload();
							win.close();
						}
					}, this);
				},
				failure : function(form, action) {
					submitButtonXsl.setDisabled(false);
					var m =Ext.decode(action.response.responseText);
					Ext.MessageBox.alert("错误",m.error);
				},
				scope : this
			});
		}else{
			submitButtonXsl.setDisabled(false);
		}
	}
	function clearPanel(){
		contSubmitPanel.form.reset();
	}
	function closeWin(){
		win.close();
	}
}
function modifySysMember_1(record){
	var btnOk =new Ext.Button({
		minWidth:70,
		id:'btnOkId',
		text:"确定",
		handler: submitPanel
	});
	var btnClear=new Ext.Button({
		minWidth:70,
		text:"清空",
		handler: clearPanel
	});
	var btnClose=new Ext.Button({
		minWidth:70,
		text:"关闭",
		handler: closeWin
	});
	var combox_arr =[['MALE','男'],['FEMALE','女']];
	var DateStore = new Ext.data.SimpleStore({
		data:combox_arr,
		fields:["sexValue","sexDis"]
	});
	var contSubmitPanel =new Ext.form.FormPanel({
		frame : true,
		defaults:{labelWidth:60,labelAlign:"right"},
		buttonAlign:'center',
		items:[{
			xtype : 'fieldset',
			 autoHeight : true,
			 items:[{
				 		layout : 'form',
						border : false,
						columnWidth : .5,
						items:[
							{height:8},
								{
									xtype:'hidden',
									name : 'id'
								},
								{
									xtype:'textfield',
									name : 'loginID',
									disabled:true,
									fieldLabel : '登录账户',
									regex:/^[^\u4e00-\u9fa5]{0,}$/,
									blankText : '登录账户为必填项',
									width : 150
								},
								{
									xtype:'textfield',
									name : 'realName',
									fieldLabel : '用户姓名',
									labelStyle:labelStyle+" width:60",
									allowBlank : false,
									blankText : '用户姓名为必填项',
									width : 150
								},
								{
									xtype:'textfield',
									//inputType:'password',
									name : 'password',
									fieldLabel : '登录密码',
									blankText : '登录密码为必填项',
									width : 150,maxLength:16,minLength:3
								},
								{
									xtype:'textfield',
									name : 'email',
									fieldLabel : '邮箱',
									labelStyle:labelStyle+" width:60",
									allowBlank : false,
									blankText : '邮箱为必填项',
									vtype:'email',
									width : 150,maxLength:58
								},
								{
									width:150,
									fieldLabel : '性别',
									xtype:'combo',
									name:'sex',
									store:DateStore,
									displayField:'sexDis',
									valueField:'sexValue',
									labelStyle:labelStyle+" width:60;",
									forceSelection:true,
									triggerAction:'all',
									emptyText:'------请选择------',
									editable:false,
									mode:'local',
									allowBlank:false,
									blankText:'性别不能为空'
								},
								{
									xtype:'numberfield',
									allowNegative:false,
									allowDecimals :false,
									regex:/^(1\d{10})$/,
									regexText:'手机输入不正确',
									fieldLabel:'移动手机',
									id:'mobile',
									maxLength:11,
									name:'mobile',
									width:150
					         },{
						         layout:'table',
						         items:[{
                                     html:'<span style="font-size:12px; text-align:right; width:60px; clear:left; float:left; padding:3px 0px 3px 0; position: relative;">固定电话:</span>'
						        		 },{
						         			 height:20,
											 xtype:'textfield',
											 allowNegative:false,
											 allowDecimals :false,
											 regex:/^\d{2,4}$/,
										 	 regexText:'电话区号输入不正确',
						         			 width:42,
						         			 id:'telzone',
						         			 maxLength:4,
						         			 name:'telCode'
						         		},{
						         			html:'-'
						         		},{
										 height:20,
										 xtype:'numberfield',
										 allowNegative:false,
										 allowDecimals :false,
										 regex:/^\d{6,9}$/,
										 regexText:'电话号码输入不正确',
										 id:'telphone',
										 name:'tel',
										 maxLength:8,
										 width:105
									}]
					    	}
						]
			 }]
		}],
		buttons:[btnOk,btnClear,btnClose]
	});

	var win =new Ext.Window({
		title:'操作用户信息修改',
		width: 266,
		items: contSubmitPanel,
		maskDisabled:true,
		resizable:false,
		autoScroll: false,
        closeAction:'close',
		draggable:true,
		modal: true,
		bodyStyle: my_scroll_cs
	});
	win.show();
    contSubmitPanel.getForm().loadRecord(record);
	function submitPanel(){
		var submitButtonXsl = Ext.getCmp('btnOkId');
		submitButtonXsl.setDisabled(true);
		if(contSubmitPanel.form.isValid()){
			var phone = Ext.getCmp('mobile').getValue();
			var telzone =  Ext.getCmp('telzone').getValue();
			var telphone =  Ext.getCmp('telphone').getValue();
			if(telzone=='' && telphone !=''){
                submitButtonXsl.setDisabled(false);
				Ext.MessageBox.alert("提示","电话号码前的区号不能为空");
				return;
			}
			if(phone=='' && telphone==''){
                submitButtonXsl.setDisabled(false);
				Ext.MessageBox.alert("提示","电话号码和手机号码不能同时为空");
				return;
			}
			contSubmitPanel.form.submit({
				waitTitle : '请稍候',
				waitMsg : '正在保存......',
                url :basepath+"/yft/sysMember/modifySysMember.html",
				success : function(form, action) {
					Ext.MessageBox.alert("系统消息", '恭喜您！操作已成功！', function(btn) {
						if(btn =='ok'){
							sysMemberListStore_1.reload();
							win.close();
						}
					}, this);
				},
				failure : function(form, action) {
					submitButtonXsl.setDisabled(false);
					var m =Ext.decode(action.response.responseText);
					Ext.MessageBox.alert("错误",m.error);
				},
				scope : this
			});
		}else{
			submitButtonXsl.setDisabled(false);
		}
	}
	function clearPanel(){
		contSubmitPanel.form.reset();
	}
	function closeWin(){
		win.close();
	}
}
function sysMemberSearch_1(){
	var roleName = Ext.util.Format.trim(Ext.getCmp('se_realName').getValue());
	sysMemberListStore_1.baseParams['roleName'] = roleName;
	sysMemberListStore_1.removeAll();
	sysMemberListStore_1.load({params:{start: 0,limit: colNum1}});
}

yft.sysMember.sysMemberListPanel =Ext.extend(Ext.Panel, {
	anthArray:'',
	closable : true,
	autoScroll : true,
	width:'auto',
	layout : "fit",
	gridViewConfig : {
		animate : true
	},
	maskDisabled : false,
	bodyStyle:my_scroll_cs,
	initComponent : function() {
		yft.sysMember.sysMemberListPanel.superclass.initComponent.call(this);
	//	alert(this.anthArray[0].data.id)
		var col =[
			{header:'登录名',dataIndex:"loginID",sortable:true,align:'center',width:100},
			{header:'姓名',dataIndex:"realName",sortable:true,align:'center',width: 100},
			{header:'性别',dataIndex:"sex",sortable:true,align:'center',width:85},
			{header:'手机',dataIndex:"mobile",sortable:true,align:'center',width:120},
			{header:'固定电话',dataIndex:"tel",sortable:true,align:'center',width:85,renderer:function(value, cellmeta, record, rowIndex){
				var htmlStr="";
				if(record.data.telCode!=''){
					htmlStr+=record.data.telCode;
					htmlStr+="-";
				}
				if(record.data.tel!=''){
					htmlStr+=record.data.tel;
				}
				return 	htmlStr;   
			}},
			{header:'邮箱',dataIndex:"email",sortable:true,align:'center',width:100},
			{header:'最近登录IP',dataIndex:"lastLoginIp",sortable:true,align:'center',width:150},
			{header:'最近登录时间',dataIndex:"lastLoginTime",sortable:true,align:'center',width:100}
		];
		
		var toolBar =[
			'-',
			{
				text : '添加',
				iconCls : 'add',
				handler : addSysMember,
				scope : this
			},'-',
			new Ext.Toolbar.Fill(),
			'登录名:&nbsp;',
			{
				xtype : 'textfield',
				id : 'se_realName',
				width : 90
			},'&nbsp;','-',{
				text : '查询',
//				iconCls : 'search',
				pressed : false,
				handler : sysMemberSearch_1,
				scope : this
			},'-'
		];
		var sysMemberListGridPanel_1 = new Ext.grid.GridPanel({
			store : sysMemberListStore_1,
			columns : col,
			//clicksToEdit:1, 
			//autoExpandColumn : 7,
			pageSize : colNum1,
			myRightclickMenu: [
				{
					text:"权限管理",
					iconCls : 'add',
					handler: function(grid ,rowIndex,cellIndex,e){
						var record = grid.getStore().getAt(rowIndex);
//						updateCompetenceForMember(record.data.id,record.data.realName);
					}
				},{
					text:"修改",
					iconCls : 'add',
					handler: function(grid ,rowIndex,cellIndex,e){
						var record = grid.getStore().getAt(rowIndex);
						modifySysMember_1(record);
					}
				}
			],
			loadMask : new Ext.LoadMask(Ext.getBody(),{msg:"数据加载中..."}),
			tbar :toolBar,
			bbar : new Ext.PagingToolbar({
				pageSize : colNum1,
				store : sysMemberListStore_1,
				displayInfo:true,
				displayMsg:'<span>显示第<span style="color:green;font-size:12px;font-weight:bold;">{0}</span>条到第<span style="color:blue;font-size:12px;font-weight:bold;">{1}</span>条记录，一共<span style="font-weight:bold;color:red;font-size:12px">{2}</span>条记录</a>',
				emptyMsg:'<span style="color:red">没有查询到相关信息<span>'
			})
		});
		sysMemberListStore_1.load({params:{start: 0,limit: colNum1}});
		this.add(sysMemberListGridPanel_1);
	}
});
